          SUBROUTINE (OID,GEN,QSIGN,LOG.MV,NEW.STAT,ERR.MSG,UET.DATA,RT.CN,SF.CN,NO.DISP.ERR,PROCESS.PO,CHRG.CC.OK,SKIP.LOGGING,PREV.JAVA.CHECKS)
** Version# 231.0001[34] - 06/30/2015 - 11:24am - TSMITH - eclipse
*** V231.0001 Change - Custom Coding . - 06/30/2015 - TSMITH - eclipse

*** Subroutine - OE.UPDATE.STATUS
*-------------------------------------------------------------------------*
*** Updates the status of an order if the status is changed at some point
*** in time.
*-------------------------------------------------------------------------*
*** OID      - Record ID for the LEDGER file (Order ID)               [IN]
*** GEN      - Value position of the data in the LED array-generation [IN]
*** QSIGN    - Quantity sign for order vs. inventory                  [IN]
*** LOG.MV   - contains the generations to log changes to            (BOTH)
*** NEW.STAT - the new status and whether this is a new order         [IN]
*** ERR.MSG  - contains an error message if there was a problem       (OUT)
***            updating the status
*** UET.DATA - Unquality Event Tracking Data                          (OUT)
*** RT.CN    - the Remit-To Vendor.  Necessary for Java in the        (IN)
***            creation of directs on the line item scheduler
*** SF.CN    - The Ship-From Vendor. Used in the same way as RT.CN    (IN)
*** NO.DISP.ERR - Whether to store or display errors.  Java wants them
***               stored and passed back out                     (IN/OUT)
*** PROCESS.PO - Set when called from solar to indicate if the PO     (IN)
***              side of the direct should be processed
*** CHRG.CC.OK - Credit authorization to override charges             (IN)
*** SKIP.LOGGING - If boolean set to true, it will prevent logging in (IN)
***                the order
*** PREV.JAVA.CHECKS - Since actions array isn't used here, we are
***             using this as a way to tell the code not to recheck
***             the "steps" that have already been checked.  We were
***             running into infinite loops if errors/prompts were
***             hit in the wrong order.  Kevin has suggested changing
***             this to use the actions array, but it's far too risky
***             to do in an EMR fix and this issue needs to be addressed.
***             The data should be value marked delimited and correlate
***             to a check that is done in this routine.              (IN)
*-------------------------------------------------------------------------*
*** Common:
*** LED - Ledger
*-------------------------------------------------------------------------*
          * Default CHRG.CC.OK to true if blank passed in
          IF CHRG.CC.OK = '' THEN
             CHRG.CC.OK = YES
          END
          ACTION.OK = YES
          PIL.OK   = NO
          UCODE    = ''
          UET.DATA = ''
          CUT.TAGS = ''
          PROC.LOT = NO

          SV.LED   = ""
          SV.LD    = ""
          PO.RECV.ASKED = NO

          READV EXC.NEW.PILS FROM CTRLFILE,'SOE.NEW.PIL.CHECK',1 ELSE
             EXC.NEW.PILS = ''
          END

          *** This is used to check to see if we need to display the
          *** inventory level message warning on return...
          READV EXC.CRD.PILS FROM CTRLFILE,'OE.RETURN.PIL.CHK',1 ELSE
             EXC.CRD.PILS = ''
          END

          *** Excluding directs from pil check
          READV EXC.DIR.PIL FROM CTRLFILE,'SOE.DIR.PIL.CHECK',1 ELSE EXC.DIR.PIL=''

          *** Make sure ERR is set to no before starting anything
          ERR = NO

          *** Find what kind of order they're working on. Also, for
          *** rentals we use the auth keys for SOE so setup a separate
          *** variable (AUTH.MODE) for checking authorization keys.
          MODE    = OID[1,1]
          IF MODE = 'R' THEN AUTH.MODE = 'S' ELSE AUTH.MODE = MODE

          *** If we are changing the status of a xfer, we will may need to
          *** update both the shipping and receiving sides, so we will
          *** set OTHER.GEN to use througout the program.
          OTHER.GEN = ''
          IF MODE = 'T' THEN
             IF GEN = 1 THEN OTHER.GEN = 2
             IF GEN = 2 THEN OTHER.GEN = 1
          END
          ONE.CANCELLED = NO

          *** Inititialize our variables.
          FND       = NO
          NO.UPD    = NO
          UPD.ALL   = YES
          ERR.MSG   = ''
          ADDL.INFO = ''
          NEW.ORDER = NEW.STAT<1,2>
          NEW.STAT  = NEW.STAT<1,1>
          BT.CN     = LED(1)<1,GEN,1>
          ST.CN     = LED(5)<1,GEN,1>
          STAG.ID  = OID:".0":GEN "R%3"
          LOC      = TRANS('PRINT.REVIEW',STAG.ID,13,'X')
          *** Due to the overuse of NO.DISP.ERR we need to save off the
          *** check auth expired so that we know we will have it later on
          *** when we actually do the authorization check. This needs to be
          *** completely redone.
          IF NO.DISP.ERR<1> = 'CHECK.AUTH.EXPIRED' AND JAVA.PROC$ THEN
             PREV.JAVA.CHECKS<1,-1> = 'CHECK.AUTH.EXPIRED'
          END

          IF OID[1,1] = 'S' AND NEW.STAT # 'X' AND LED(129)<1,2> THEN
             OE.UPDATE.CHANGE.ORDER OID,GEN,QSIGN,LOG.MV,NEW.STAT,ERR.MSG,UET.DATA,RT.CN,SF.CN,NO.DISP.ERR
             RETURN
          END

          *** Setup the new status and old status (if it didn't change
          *** leave this routine).
          NS = NEW.STAT<1,1,1>
          OS = LED(6)<1,GEN,1>
          IF NS = OS THEN RETURN

          *** If we are changing the status on the order, then we need to
          *** check to make sure that if values have been overridden that
          *** they have the the correct authorization for to override
          *** values (e.g. cogs/cost).  If they do not have the
          *** authorization as necessary, set them back to the default.
          IF LED(33)<1,GEN> AND NS # 'X' THEN
             LDIDS   = RAISE(LED(48)<1,GEN>)
             LDID.CT = DCOUNT(LDIDS,VM)
             *** loop through all of the line items to check for auth.
             FOR L = 1 TO LDID.CT
                LDID = LDIDS<1,L>
                LD.GET LDID
                IF NOT(NUM(LD(1))) OR LD(1) = '' THEN CONTINUE
                OE.CHECK.OVRD.AUTH OID,GEN,LDID,OS,NS
             NEXT LDID
          END

          *** If a Sales Order gen is currently in a Bid or Cancelled
          *** status and the user is intending to invoice it, we must first
          *** (automatically) change to the order to a Call When Complete.
          *** By doing so, inventory will be properly checked when the
          *** order is invoiced

          * Flag to update LEDGER.TOTALS
          UPD.LED.STATS$ = YES

          *** DO NOT DELETE THE NEXT 4 LINES OF CODE. THIS IS
          *** INTENTIONALLY RECURSIVE.
          IF (MODE='S' AND (OS='B' OR OS='X') AND (NS='I' OR NS='P')) THEN
             MATBUILD SV.LED FROM LED
             OE.UPDATE.STATUS OID,GEN,QSIGN,LOG.MV,'C',ERR.MSG,UET.DATA,,,,,,YES
             IF ERR.MSG THEN GOTO ABORT
          END

          *** Check to see if we should prompt the user for consolidating
          *** the line items...
          IF MODE='S' AND OS='B' AND NS#'B' AND NS#'I' AND NS#'P' AND NS#'X' THEN
             IF LED(98)<1,GEN> THEN GOTO NO.CONSOL

             *** Read in the BR-specific control record.
             BR = LED(2)<1,GEN,2>
             CTRL.ID = 'CONSOLIDATE.LINE.ITEMS~':BR
             READ CONSOL.IT FROM CTRBFILE,CTRL.ID ELSE CONSOL.IT = NO

             *** Don't bother if the control record isn't set.
             IF NOT(CONSOL.IT) THEN GOTO NO.CONSOL

             *** See if there is anything that needs to be consolidated.
             SOE.CHECK.LI.CONSOL OID,GEN,AZ,SORT.LDID,STOL.LIST,DO.IT
             IF NOT(DO.IT) THEN GOTO NO.CONSOL

             *** If consolidation is possible, see if the user wants to.
             MSG = 'Consolidate Like Line Items (Y/N) : '
             GOSUB CONFIRM
             IF ERR THEN GOTO NO.CONSOL

             *** Do the actual consolidation.
             SOE.APPLY.LI.CONSOL OID,GEN,QSIGN,SORT.LDID,STOL.LIST
          END
NO.CONSOL:***
          *** Update the PIL if this is a sales order with a status of BID
          *** ane we are changing it to something other than 'X' or vice
          *** versa.
          IF (OS='B' AND NS#'X') OR (OS='X' AND NS#'B') AND MODE = 'S' THEN
             BR = LED(2)<1,GEN,2>
             LDIDS= RAISE(LED(48)<1,GEN>)
             NUM.LNS = DCOUNT(LDIDS,VM)
             FOR L = 1 TO NUM.LNS
                LDID = LDIDS<1,L>
                PIL = ''
                LD.GET LDID
                IF NOT(NUM(LD(1))) OR LD(1) = '' THEN CONTINUE
                MAT OLD.LD = MAT LD

                PIL.PN = LD(1)
                MATREAD PRD FROM PRDFILE,PIL.PN ELSE MAT PRD = ''

                WBRS = BR
                IF NOT(NO.NETWORK.PIL$) THEN
                   GET.PCGID PCGID,PRD(18),PRD(12)
                   WHSE.FOR.ME WHSE,BR,PCGID
                   WHSE.LIST WBRS,WHSE,PCGID
                   WBRS = WBRS<1>
                END
                PIL  = ''
                GET.PIL PIL,WBRS,PIL.PN,DATE()
                LD(69)<1,1> = PIL
                IF PRD(106) THEN
                   OE.GET.DKIT.COMPS OID,GEN,BR,LD(1),LDID
                END
                OE.COMMT.QTYS OID,LDID,QSIGN,GEN

                IF OS = 'B' THEN
                   LD(139)<1,GEN> = DATE()
                END
                UPDATE.LEDGER.DET OID,LDID,QSIGN
             NEXT L
             UPDATE.LEDGER OID,GEN
          END

           IF NS = 'B' AND MODE = 'S' THEN
             LDIDS= RAISE(LED(48)<1,GEN>)
             NUM.LNS = DCOUNT(LDIDS,VM)
             FOR L = 1 TO NUM.LNS
                LDID = LDIDS<1,L>
                PIL = ''
                LD.GET LDID
                IF NOT(NUM(LD(1))) OR LD(1) = '' THEN CONTINUE
                MAT OLD.LD = MAT LD

                LD(139)<1,GEN> = ""

                UPDATE.LEDGER.DET OID,LDID,QSIGN
             NEXT L
             UPDATE.LEDGER OID,GEN
          END

          *** This line of code has to stay after the initial PIL update
          *** or they will get an error on the ABORT of an illegal ledger
          *** update.
          MATBUILD SV.LED FROM LED

          *** If this is a "drop point" we cannot cancel the gen until
          *** that drop point is re-assigned to a different generation.
          IF MODE = 'P' AND NEW.STAT = 'X' THEN
             RCV.BR = LED(2)<1,GEN,2>
             OE.DROP.POINT.GET RCV.BR,GEN,DRP.PT
             IF DRP.PT THEN
                ERR.MSG = 'Receiving Branch on this Gen is defined '
                ERR.MSG<-1> = 'as a Drop Point for other branches on this order.'
                GOTO ABORT
             END
          END

          * We need to check to see if this Order is on a Payable and they
          * are trying to cancel or return to order. If so, don't let them
          CHECK.PO = (MODE = 'P' AND NEW.STAT # 'R')
          CHECK.SO = (MODE = 'S' AND LED(33)<1,GEN> AND NEW.STAT # 'I')
          IF LED(8)<1,GEN> AND (CHECK.PO OR CHECK.SO) THEN
             CHK.GEN = GEN

             * Flip over to the PO side of the direct invoice if not
             * already on it
             IF CHECK.SO AND LED(6)<1,GEN> # 'Y' THEN
                LOCATE LED(33)<1,GEN> IN LED(12)<1> SETTING CHK.GEN ELSE
                   CHK.GEN = GEN
                END
             END

             * Check to see if order has been reconciled or paid
             GOSUB CHECK.AP

             * Set up error messages and abort out of update
             BEGIN CASE
             CASE IS.PAID
                ERR.MSG     = 'This Order was Paid on ':AR.ID
                ERR.MSG<-1> = 'Unable to Change Status Unless Payment '
                ERR.MSG    := 'is Cancelled First'
                GOTO ABORT
             CASE IS.RECD
                ERR.MSG     = 'This Order is Reconciled on ':AR.ID
                ERR.MSG<-1> = 'Unable to Change Status Unless Order '
                ERR.MSG    := 'is Unreconciled'
                GOTO ABORT
             END CASE
          END

          *** Make sure lot item (lot billing) are on a direct or bid only
          IF NS # 'D' AND NS # 'B' AND NS # 'X' THEN
             GOSUB CHK.LOT
             IF NOT(LOT.OK) THEN
                ERR.MSG = "Lot Item GEN, Use A/P Entry to Process."
                GOTO ABORT
             END
          END

          * Check to see if we need to update quantities on an original
          * order due to a return being canceled or re-opened
          IF ((NS = "X") OR (OS = "X")) THEN
             GOSUB CHK.RETURNS
          END

          *** Make sure the new status is a "valid" status to Eclipse.
          OE.STATUS.CONV OID,GEN,NS,STAT.DESC,INVALID.STAT
          IF INVALID.STAT THEN
             ERR.MSG = 'Invalid Status'
             GOTO ABORT
          END

          *** They cannot update a generation that has items in a closed
          *** accounting period.
          IF LED(8)<1,GEN> THEN
             CHK.GL.POST LED(23)<1,GEN>,OK,MODE,LED(6)<1,GEN>
             IF NOT(OK) THEN
                ERR.MSG = 'Item is in Closed Accting Period'
                GOTO ABORT
             END
          END
          *** If the user is trying to update an xfer gen, both the
          *** shipping and receiving generations must be in open acctg
          *** periods.  So we will check "OTHER.GEN" here...
          IF OTHER.GEN AND (NS = 'X' OR LED(6)<1,OTHER.GEN> = 'X') THEN
             IF LED(8)<1,OTHER.GEN> THEN
                CHK.GL.POST LED(23)<1,OTHER.GEN>,OK,MODE,LED(6)<1,OTHER.GEN>
                IF NOT(OK) THEN
                   ERR.MSG = 'Item is in Closed Accting Period'
                   GEN = OTHER.GEN
                   GOTO ABORT
                END
             END
          END

          *** If Java has already checked this, skip it and reset
          *** NO.DISP.ERR.
          NOT.RCVD = NO
          FINDSTR 'Tagged Qtys Have Not Been Completely Received' IN NO.DISP.ERR<1,1> SETTING POS THEN NOT.RCVD = YES

          SKIP.CHECK = NO
          LOCATE 'OE.TAGGED.QTY.EDIT' IN PREV.JAVA.CHECKS<1> SETTING SKIP.POS THEN
             SKIP.CHECK = YES
          END ELSE
             SKIP.CHECK = NO
          END

          BEGIN CASE
          CASE SKIP.CHECK = YES AND NO.DISP.ERR<1,2> # 'OE.TAGGED.QTY.EDIT'
             * Don't do anything here - we just don't want this checked again.
          CASE SKIP.CHECK = YES AND NO.DISP.ERR<1,2> = 'OE.TAGGED.QTY.EDIT'
             NO.DISP.ERR = YES
          CASE (NO.DISP.ERR<1,2> # 'OE.TAGGED.QTY.EDIT') AND NOT(NOT.RCVD)
             IF JAVA.PROC$ THEN
                PREV.JAVA.CHECKS<1,-1> = 'OE.TAGGED.QTY.EDIT'
             END
             * This is either the first time through for Solar or this is
             * being called from ETERM.
             IF NS='B' OR NS='X' THEN
                * Check and perform any pending updates. We need to update
                * ledger and reset the SV.LED because the updates in
                * UPDATE.LEDGER.CHECK must be saved regardless
                UPDATE.LEDGER.CHECK OID,GEN
                UPDATE.LEDGER OID,GEN
                MATBUILD SV.LED FROM LED

                OE.CHECK.ALL.TAG OID, GEN, CHNG.OK,NO.DISP.ERR,CUT.TAGS
                IF NOT(CHNG.OK) THEN GOTO ABORT
                *** check other side of transfer
                IF OTHER.GEN THEN
                   * Check and perform any pending updates. We need to
                   * update ledger and reset the SV.LED because the update
                   * in UPDATE.LEDGER.CHECK must be saved regardless
                   UPDATE.LEDGER.CHECK OID,OTHER.GEN
                   UPDATE.LEDGER OID,OTHER.GEN
                   MATBUILD SV.LED FROM LED
                   OE.CHECK.ALL.TAG OID,OTHER.GEN,CHNG.OK,NO.DISP.ERR

                   IF NOT(CHNG.OK) THEN
                      GEN = OTHER.GEN
                      GOTO ABORT
                   END
                END
             END

             *** Check all tags to make sure the inventory has been
             *** received
             IF NS='I' AND OID[1,1]='S' THEN
                OE.CHECK.RCV.TAG OID, GEN, CHNG.OK,NO.DISP.ERR
                IF NOT(CHNG.OK) THEN GOTO ABORT
             END
          CASE (NO.DISP.ERR<1,2> = 'OE.TAGGED.QTY.EDIT') AND NOT(NOT.RCVD)
             * If the user has accepted the "break tag" prompt from solar
             * then we need to go ahead and update the tag information
             IF JAVA.PROC$ THEN
                PREV.JAVA.CHECKS<1,-1> = 'OE.TAGGED.QTY.EDIT'
             END
             IF NS='B' OR NS='X' THEN
                NO.DISP.ERR = YES
                *** Check for any pending updates
                UPDATE.LEDGER.CHECK OID,GEN
                *** check other side of transfer
                IF OTHER.GEN THEN
                   UPDATE.LEDGER.CHECK OID,OTHER.GEN
                END

             END
          CASE OTHERWISE
             NO.DISP.ERR = YES
          END CASE

          NEXT.STAT = ''
          IF NS = 'P' THEN
             READV NEXT.STAT FROM SVIAFILE,LED(70)<1,GEN>,7 ELSE
                NEXT.STAT = ''
             END
          END

          SER.STATS    = 'I'
          IF NEXT.STAT = 'I' THEN
             SER.STATS<1,-1> = 'P'
          END

          IF SOE.SERIAL.TICK$ THEN
             SER.STATS<1,-1> = 'T'
          END

          IF OID[1,1] = 'S' AND LED(110)<1,GEN> # 'B' THEN
             SERL.FLAG = ''
             LOCATE NS IN SER.STATS<1> SETTING SPOS THEN
                READV SERL.FLAG FROM CTRLFILE,'SOE.SERIAL.PROCESS',1 ELSE
                   SERL.FLAG = ''
                END
             END
             IF SERL.FLAG THEN GOSUB CHK.SERS ELSE ERR = NO
             IF ERR THEN GOTO ABORT
          END

          *** Check Product Inventory Levels only if status change affects
          *** them.

          BEGIN CASE
          CASE (MODE = 'S' OR MODE = 'T') AND (NS='D' OR NS='B' OR NS='X') AND OS#'B' AND OS#'D' AND OS # 'X'
             IF OS='I' AND LED(33)<1,GEN> THEN GOTO SKIP.INV.DIR
             GOSUB CHK.PILS
             IF NOT(PIL.OK) THEN GOTO ABORT
             *** Check "other gen" pil level before allowing update
             IF OTHER.GEN THEN
                SV.GEN = GEN
                GEN = OTHER.GEN
                GOSUB CHK.PILS
                IF NOT(PIL.OK) THEN GOTO ABORT
                GEN = SV.GEN
             END
          CASE MODE = 'S' AND (OS='X' OR OS='B' OR OS='D') AND NS#'X' AND NS#'B' AND NS#'D'
             SVQSIGN = QSIGN
             QSIGN = 1
             GOSUB CHK.PILS
             QSIGN = SVQSIGN
             IF NOT(PIL.OK) THEN GOTO ABORT
             * If this has been checked before see if the
             * job queue needs to get updated.
             LOCATE 'SOE.INV.FAC.CHECK' IN PREV.JAVA.CHECKS<1> SETTING NOTHING THEN
                IF NO.DISP.ERR<2> = 'SOE.INV.FAC.CHECK' THEN
                   PRD.PN.LIST = RAISE(NO.DISP.ERR<3>)
                   GOSUB UPD.JQ
                END
                NO.DISP.ERR = YES
             END ELSE
                GOSUB CHK.INV.FAC
                IF NOT(INV.FAC.OK) THEN GOTO ABORT
             END
          CASE MODE = 'P' AND NS # 'B' AND NS # 'X' AND (OS='X' OR OS='B')
             GOSUB CHK.PILS
             IF NOT(PIL.OK) THEN GOTO ABORT
          END CASE
SKIP.INV.DIR:   *
          IF NS='X' THEN GOTO CANCEL.IT

          *** Bid / Direct Mode
          IF (OS='' OR OS='B' OR OS='D') AND (NS#'B' AND NS#'D') THEN
             *** Reset print style if changing mode from Bid to Non-Bid
             IF OS='B' THEN
                IF MODE = 'S' THEN
                   OE.OK = YES

                   *** JAVA.PROC$ does this check in a separate subroutine
                   IF NOT(JAVA.PROC$) THEN
                      OE.CHECK.CREDIT.RELEASE OID,GEN,QSIGN,,,,OE.OK

                      IF NOT(OE.OK) THEN
                         OE.OK = NO
                         PRMPT = 'Allow Order Entry'
                         INCLUDE.BID = YES
                         SOE.CHECK.CREDIT.RELEASE OID,GEN,PRMPT,,OE.OK,,1,INCLUDE.BID
                         IF NOT(OE.OK) THEN
                            ERR.MSG = 'No Order Entry Allowed!'
                            GOTO ABORT
                         END
                      END
                   END
                END

                IF NS # 'I' AND NOT(LED(98)<1,GEN>) THEN
                   * Check if Solar has already checked for authorize
                   * use of expired pricing.  If authorized, we return here
                   * and continue (if not authorized, process is aborted
                   * in Solar).
                   EXP.BID.CHECKED = NO
                   LOCATE 'CHECK.AUTH.EXPIRED' IN PREV.JAVA.CHECKS<1> SETTING NOTHING THEN
                      EXP.BID.CHECKED = YES
                      NO.DISP.ERR     = YES
                   END

                   DISPLAY.OPTIONS = NO
                   IF NOT(EXP.BID.CHECKED) AND NOT(PHANTOM.PROC) THEN
                      GOSUB CHK.EXP.BID.PRC
                   END
                   IF DISPLAY.OPTIONS THEN
                      IF (JAVA.PROC$) THEN
                         NO.DISP.ERR<1> = "CHECK.AUTH.EXPIRED"
                         GOTO ABORT
                      END ELSE
                         GOSUB AUTH.EXP.BID.PRC
                         IF ERR.MSG THEN GOTO ABORT
                      END
                   END
                END
             END
             GOSUB UPD.OLD.STAT
             LED(6)<1,GEN> = NS

             CHG.SHIP.DATE = NO
             IF (OS = 'B') THEN
                * Change shipdate to Earliest avail if later than
                * current shipdate.
                OE.EARLIEST.SHIPDATE OID,GEN,EARLIEST.DATE
                IF EARLIEST.DATE > LED(9)<1,GEN> THEN
                   ******************************************************
                   *This is what is happening: OE.CHANGE.SHIPDATE will
                   *commit the item, change inventory and add the order
                   *to future ledger. This is happening before all the
                   *prompts for confirmation and PIL check. So even if user
                   *reponds no to confirm and overcommit, inventory will
                   *not be undone because the status will be back at "B" in
                   *the case of a returned purchase order.
                   *What I'm trying to do down here is to prompt the user
                   *for confirmation and overcommit before committing the
                   *item(s)
                   ***********************************>>>>>>>>

                   IF MODE = 'P' AND NS = 'R' AND LED(8)<1,GEN>='' THEN
                      MSG = 'Receive qtys for ':OCONV(LED(9)<1,GEN>,'D4/'):' (Y/N) : '
                      GOSUB CONFIRM
                      IF ERR THEN GOTO ABORT
                      * Check to see if the user is trying to receive
                      * product in the wrong branch for purchase orders
                      * and transfers.
                      GOSUB CHK.RCV.MSG
                      IF RMSG AND NOT(JAVA.PROC$) THEN
                         MSG = RMSG
                         GOSUB CONFIRM
                         IF ERR THEN GOTO ABORT
                      END
                      * If this is a return P/O then we need to make sure
                      * that we have enough in stock to return.
                      IF NOT(JAVA.PROC$) AND NOT(PHANTOM.PROC) THEN
                         OE.CHECK.OVERCOMMIT OID,GEN,DATE(),QSIGN,LOG.MV,ERR.MSG
                         IF ERR.MSG THEN GOTO ABORT
                      END
                      PO.RECV.ASKED = YES
                   END
                   ******************************************************
                   * While changing a Bid to Ship When Specified don't
                   * change ship date until after the over commit check.
                   * Otherwise, change the ship date to the earliest
                   * available ship date.
                   IF NS = 'S' THEN
                      CHG.SHIP.DATE = YES
                   END ELSE
                      OE.CHANGE.SHIPDATE OID,GEN,EARLIEST.DATE,QSIGN,LOG.MV
                   END
                END
             END

             * This will need to be fixed
             *** Don't check here if going from 'D'irect to 'P'ick Up Now.
             *** We'll check this a little later for TODAY.
             IF NOT(JAVA.PROC$) AND NOT(NS='P' AND OS='D') THEN
                OE.CHECK.OVERCOMMIT OID,GEN,LED(9)<1,GEN>,QSIGN,LOG.MV,ERR.MSG
                IF ERR.MSG THEN GOTO ABORT
             END

             * While changing a Bid to Ship When Specified don't change
             * the ship date until after the over commit check.
             * Changing it earlier invalidates the check so user
             * never gets prompted/warned.
             IF CHG.SHIP.DATE THEN
                OE.CHANGE.SHIPDATE OID,GEN,EARLIEST.DATE,QSIGN,LOG.MV
             END
          END

          IF NS='B' OR NS='D' OR OS='B' OR OS='D' THEN UPD.ALL = YES

          *** If order is being reinvoiced after cancel, update
          *** total freight and handling (if any) BEFORE setting new
          *** stat to 'I'
          IF LED(8)<1,GEN> AND NS = 'I' AND OS = 'X' THEN
             IF LED(57)<1,1> AND (LED(36)<1,GEN,1> = 4 OR LED(36)<1,GEN,1> = 7) THEN
                OE.CALC.FGHT OID,GEN,FGHT
                LED(36)<1,GEN,4> = FGHT*QSIGN
                *** Add used freight
                LED(57)<1,3> += FGHT
             END
             IF LED(57)<1,2> AND LED(36)<1,GEN,2> = 4 THEN
                OE.CALC.HNDL OID,GEN,HNDL
                LED(36)<1,GEN,8> = HNDL*QSIGN
                *** Add used handling
                LED(57)<1,4> += HNDL
             END
          END

          GOSUB UPD.OLD.STAT
          LED(6)<1,GEN> = NS

          *** Cancel mode:  If Status was Cancel, recalc new shipdate and
          *** total freight
          IF OS='X' OR LED(9)<1,GEN>+0=0 OR LED(9)<1,GEN> > 99999 THEN
             IF LED(8)<1,GEN> OR NS='D' THEN
                * ---------- *
                * If this is a Java proc then the logic to get the
                * new ship date has already been done.  It was already
                * placed into LED(9)<1,GEN> so skip this section
                IF NOT(JAVA.PROC$) THEN
                   WINDOW ,,40,3,3
                   PRINT @(0,1):'Enter Shipdate : '
IN.POSTDT:         INP NEW.SHPDT,17,1,10,'D4/'
                   IF F12 THEN
                      WINDOW.CLOSE
                      GOTO ABORT
                   END
                   IF NEW.SHPDT='' THEN GOTO IN.POSTDT
                   CHK.GL.POST NEW.SHPDT,OK,MODE
                   IF NOT(OK) THEN
                      MESS 10,5,'Shipdate is in closed accounting period'
                      GOTO IN.POSTDT
                   END
                   WINDOW.CLOSE
                END ELSE
                   NEW.SHPDT = LED(9)<1,GEN>
                END
                * ---------- *
                IF LED(8)<1,GEN> THEN
                   BEGIN CASE
                   CASE MODE='T' OR MODE = 'W'
                   CASE MODE='S' AND NS#'I'
                   CASE MODE='P' AND NS#'R'
                   CASE OTHERWISE
                      LED(23)<1,GEN> = NEW.SHPDT + 0
                      OE.CALC.TERMS OID,GEN
                   END CASE
                END
             END ELSE
                IF MODE # 'W' THEN
                   OE.EARLIEST.SHIPDATE OID,GEN,NEW.SHPDT
                END
             END
             LED(9)<1,GEN> = NEW.SHPDT + 0
             LED(132)<1,GEN> = ''
             UPD.ALL = YES
          END

          * ------------------- *

          *** If going from Bid to something else, check the control rec
          *** and update the ship date if necessary
          IF OS = 'B' AND NS # 'X' THEN
             CTRB.ID = "BID.DATE.TO.ORDER~":LED(2)<1,GEN,1>
             READV UPD.BR FROM CTRBFILE,CTRB.ID,1 ELSE UPD.BR = ''
             IF UPD.BR THEN
                LED(4)<1,GEN> = DATE()
             END
          END

          IF OS='T' AND NS#'I' THEN
             * Reset Print log to no documents printed
             READVU PRT.LOG FROM LEDLFILE,OID,1 ELSE PRT.LOG = ''
             PRT.LOG<1,GEN> = ''
             WRITEV PRT.LOG ON LEDLFILE,OID,1
          END

          BEGIN CASE
          CASE MODE = 'S'
             IF LED(30)<1,GEN> = 'Y' THEN PRINT BELL:; GOTO ABORT
             * Invoice open order
             IF NS = 'I' AND LED(8)<1,GEN> = '' THEN
                IF NOT(INSIDE.ROE$) THEN
                   MSG = 'Invoice ':OCONV(LED(9)<1,GEN>,'D4/'):' shipdate (Y/N) : '
                   GOSUB CONFIRM
                   IF ERR THEN GOTO ABORT

                   * Setup all the necessary LEDGER attributes so that
                   * we can do a credit check
                   OE.CHANGE.SHIPDATE OID,GEN,DATE(),QSIGN,LOG.MV,NO,EMSG,YES
                   IF EMSG THEN
                      ERR.MSG = EMSG
                      GOTO ABORT
                   END
                END
                SOE.CREDIT.CHECK LED(5)<1,GEN>,,,,NO.SHIP,,,OID,GEN
                PRT.OK = YES
                IF NO.SHIP THEN
                   IF NOT(JAVA.PROC$) THEN
                      PRMPT    = 'Release a Shipping Ticket'
                      SOE.CHECK.CREDIT.RELEASE OID,GEN,PRMPT,YES,PRT.OK,,2
                   END
                END
                IF NOT(PRT.OK) THEN GOTO ABORT

                * We are calling OE.CHANGE.SHIPDATE again with a good
                * reason. The first call just sets the data up (doesn't
                * commit) because we need to do a credit check and there
                * is a possibility that the user isn't authorized to
                * release the credit hold. This call to OE.CHANGE.SHIPDATE
                * will actually commit the information before
                * OE.PROCESS.ORDER is called.
                IF NOT(INSIDE.ROE$) THEN
                   OE.CHANGE.SHIPDATE OID,GEN,DATE(),QSIGN,LOG.MV,YES,EMSG
                   IF EMSG THEN
                      ERR.MSG = EMSG
                      GOTO ABORT
                   END
                END

                PROCESS.ERR = ''
                ADDL = ''
                IF MODE = 'S' AND NEW.STAT = 'I' THEN ADDL<1,1> = NO
                OE.PROCESS.ORDER OID,GEN,,UET.DATA,PROCESS.ERR,CHRG.CC.OK,ADDL

                *** If for any reason OE.PROCESS.ORDER does not invoice
                *** the generation (credit card auto auth is one reason..)
                *** then abort from process
                IF LED(8)<1,GEN> = '' OR PROCESS.ERR THEN
                   GOSUB UPD.OLD.STAT
                   * If we changed status in OE.PROCESS.ORDER, we need to
                   * save it here
                   SV.LED<6,GEN> = LED(6)<1,GEN>
                   IF PROCESS.ERR THEN
                      ERR.MSG = PROCESS.ERR
                   END ELSE
                      ERR.MSG = 'Operation Aborted'
                   END
                   GOTO ABORT
                END

                IF INSIDE.ROE$ THEN
                   ORD.ID = OID:'.':LED(12)<1,GEN>
                   RF.INPROCESS.CLOSE ORD.ID
                END
                OE.CHECK.INPROCESS OID,GEN
                * Code to ask if they want to process the direct GEN as
                * well. Note that if we are processing the S/O side of
                * a Direct Lot, then by definition the P/O side must
                * already be processed as that is the only time we allow
                * processing a Direct Lot S/O through this flow.
                IF (OS = "D" AND NOT(PROC.LOT)) THEN
                   MSG = 'Process P/O Generation as Well (Y/N) : '
                   LOCATE LED(12)<1,GEN> IN LED(33)<1> SETTING DGEN THEN
                      GOSUB CONFIRM
                      * If this is not from solar and there were no errors
                      * then process the direct. If we came from solar
                      * and only if the user has specifically requested
                      * that the P/O be processed, process the order.
                      IF (NOT(ERR) AND NOT(JAVA.PROC$)) OR (JAVA.PROC$ AND PROCESS.PO) THEN
                         *** Process the direct side
                         OE.PROCESS.DIRECT OID,GEN,DGEN
                      END
                   END
                END
                NO.UPD = YES

                *** Remove record from OOSRQ
                READV PRT.STATS FROM LEDLFILE,OID,9 ELSE PRT.STATS = ''
                IF PRT.STATS<1,GEN> # 'M' THEN
                   PRVW.ID = OID:'.':LED(12)<1,GEN> "R%4"
                   DELETE PRVWFILE,PRVW.ID
                END
             END
             *** Return Invoice/Change Ship Ticket to Order...
             IF LED(8)<1,GEN> AND NS#'I' THEN
                IMSG = 'Return Invoice # :':OID:'.':LED(8)<1,GEN>"R%3"

                BEGIN CASE
                CASE NS#'B'
                   MSG = IMSG:' to Order (Y/N) : '
                CASE OTHERWISE
                   MSG = IMSG:' to Bid (Y/N) : '
                END CASE

                GOSUB CONFIRM
                IF ERR THEN
                   ERR.MSG        = 'Operation Aborted'
                   GOTO ABORT
                END

                *** If this is a transfer we need to check the "other gen"
                *** to see if it should be returned to the order
                IF OTHER.GEN THEN
                   IF LED(6)<1,OTHER.GEN> = 'X' THEN
                      MSG = 'Return Transfer # ':OID:'.':LED(8)<1,OTHER.GEN>"R%3":' to order (Y/N) : '
                      GOSUB CONFIRM
                      SV.GEN = GEN
                      GEN = OTHER.GEN
                      IF ERR THEN GOTO ABORT
                      LED(6)<1,GEN> = 'O'
                      GEN = SV.GEN
                      LOGMV = OTHER.GEN
                      OE.RETURN.TO.ORDER OID,OTHER.GEN,QSIGN,LOGMV
                   END
                END
                * warn user if there are payments attached the invoice
                CHECK.AUTH = NO
                GOSUB CHECK.PAYMENTS
                IF NOT(ACTION.OK) THEN GOTO ABORT
                OE.RETURN.TO.ORDER OID,GEN,QSIGN,LOG.MV
                NO.UPD = YES
             END

             IF NS='D' AND NOT(LED(33)<1,GEN>) THEN
IN.DIR:         OE.DIRECT.MODE OID,GEN,QSIGN,LOG.MV,OS,RT.CN,SF.CN
                IF ERR AND OS='I' THEN GOTO IN.DIR
                IF ERR THEN
                   ERR.MSG = 'Operation Aborted'
                   GOTO ABORT
                END
                IF NOT(JAVA.PROC$) THEN
                   REMINDER.VIEW BT.CN,,12,80,23
                   IF ST.CN # BT.CN THEN
                      REMINDER.VIEW ST.CN,,12,80,23
                   END
                END
             END
             IF NS='P' AND OS#'I' THEN
                CHK.AVAIL = YES
                OE.CHANGE.SHIPDATE OID,GEN,DATE(),QSIGN,LOG.MV,CHK.AVAIL,ERR.MSG
                IF ERR.MSG THEN
                   GOTO ABORT
                END
             END
             IF NS='T' OR OS='T' THEN UPD.ALL = YES
          CASE MODE = 'P'
             IF NS='R' AND LED(8)<1,GEN>='' THEN
                IF NOT(PO.RECV.ASKED) THEN
                   MSG = 'Receive qtys for ':OCONV(LED(9)<1,GEN>,'D4/'):' (Y/N) : '
                   GOSUB CONFIRM
                   IF ERR THEN GOTO ABORT
                   *** Check to see if the user is trying to receive product
                   *** in the wrong branch for purchase orders and transfers
                   GOSUB CHK.RCV.MSG
                   IF RMSG AND NOT(JAVA.PROC$) THEN
                      MSG = RMSG
                      GOSUB CONFIRM
                      IF ERR THEN GOTO ABORT
                   END
                END
                IF LED(8)<1,GEN>='' THEN
                   * If this is a return P/O then we need to make sure that
                   * we have enough in stock to return *

                   IF NOT(PO.RECV.ASKED) AND NOT(JAVA.PROC$) AND NOT(PHANTOM.PROC) THEN
                      OE.CHECK.OVERCOMMIT OID,GEN,DATE(),QSIGN,LOG.MV,ERR.MSG
                      IF ERR.MSG THEN GOTO ABORT
                   END
                   OE.PROCESS.ORDER OID,GEN,,UET.DATA,,CHRG.CC.OK
                   NO.UPD = YES
                END
             END

             IF OS = 'R' THEN
                MSG = 'Return Receiving #':OID:'.':LED(8)<1,GEN>"R%3":' to order (Y/N) : '
                GOSUB CONFIRM
                IF ERR THEN GOTO ABORT
                OE.RETURN.TO.ORDER OID,GEN,QSIGN,LOG.MV
                NO.UPD = YES
             END
             IF OS = 'X' AND LED(8)<1,GEN> THEN
                NS       = 'R'
                NEW.STAT = 'R'
                LED(6)<1,GEN> = 'R'
             END
          CASE MODE = 'T'
             BEGIN CASE
             CASE GEN=1 AND NS='O' AND LED(6)<1,2>='R'
                PRINT BELL:; GOTO ABORT
             CASE NS='S' OR NS='R' AND LED(8)<1,GEN>
                PRINT BELL:; GOTO ABORT
             CASE NS='S' AND LED(30)<1,GEN>#'SX'
                PRINT BELL:; GOTO ABORT
             CASE NS='R' AND LED(30)<1,GEN>#'RX'
                PRINT BELL:; GOTO ABORT
             CASE NS='R' AND NOT(LED(8)<1,1>)
                PRINT BELL:; GOTO ABORT
             CASE LED(8)<1,GEN> AND (NS#'S' AND NS#'R')
                MSG = 'Return Transfer # ':OID:'.':LED(8)<1,GEN>"R%3":' to order (Y/N) : '
                GOSUB CONFIRM
                IF ERR THEN GOTO ABORT
                *** If this is a transfer we need to check the "other gen"
                *** to see if it should be returned to the order
                IF OTHER.GEN THEN
                   IF LED(6)<1,OTHER.GEN> = 'X' THEN
                      MSG = 'Return Transfer # ':OID:'.':LED(8)<1,OTHER.GEN>"R%3":' to order (Y/N) : '
                      GOSUB CONFIRM
                      SV.GEN = GEN
                      GEN = OTHER.GEN
                      IF ERR THEN GOTO ABORT
                      LED(6)<1,GEN> = NS
                      GEN = SV.GEN
                      LOGMV = OTHER.GEN
                      OE.RETURN.TO.ORDER OID,OTHER.GEN,QSIGN,LOGMV
                   END
                END
                OE.RETURN.TO.ORDER OID,GEN,QSIGN,LOG.MV
             CASE LED(8)<1,GEN>='' AND (NS = 'S' OR NS = 'R')
                MSG = 'qtys on ':OCONV(LED(9)<1,GEN>,'D4/'):' (Y/N) : '
                IF LED(30)<1,GEN>='SX' THEN
                   MSG = 'Ship ':MSG
                END ELSE
                   MSG = 'Receive ':MSG
                END
                GOSUB CONFIRM
                IF ERR THEN GOTO ABORT

                *** Check to see if the user is trying to receive product
                *** in the wrong branch for purchase orders and transfers
                GOSUB CHK.RCV.MSG
                IF RMSG AND NOT(JAVA.PROC$) THEN
                   MSG = RMSG
                   GOSUB CONFIRM
                   IF ERR THEN GOTO ABORT
                END

                *** Make sure this is on the shelf if we're going to ship
                *** it now.
                IF NS = 'S' THEN
                   CHK.AVAIL = YES
                   OE.CHANGE.SHIPDATE OID,GEN,DATE(),QSIGN,LOG.MV,CHK.AVAIL,ERR.MSG
                   IF ERR.MSG THEN
                      GOTO ABORT
                   END
                END
                OE.PROCESS.ORDER OID,GEN,,UET.DATA,,CHRG.CC.OK

                *** When receiving a transfer, we can delete any OOSRQ
                IF NS = 'R' THEN
                   READV PRT.STATS FROM LEDLFILE,OID,9 ELSE PRT.STATS = ''
                   IF PRT.STATS<1,GEN> # 'M' THEN
                      PRVW.ID = OID:'.':LED(12)<1,GEN> "R%4"
                      DELETE PRVWFILE,PRVW.ID
                   END
                   IF OTHER.GEN THEN
                      IF PRT.STATS<1,OTHER.GEN> # 'M' THEN
                         PRVW.ID = OID:'.':LED(12)<1,OTHER.GEN> "R%4"
                         DELETE PRVWFILE,PRVW.ID
                      END
                   END
                END
                NO.UPD = YES
             END CASE
          CASE MODE = 'W'
             BEGIN CASE
             CASE NS = 'C' AND LED(6)<1,GEN> # 'I'
                PRINT BELL:; RETURN
             CASE LED(8)<1,GEN> = '' AND (NS = 'C' OR NS = 'I')
                IF NS = 'I' THEN
                   MSG = 'Start Process'
                END ELSE
                   MSG = 'Complete Process'
                END
                IF ERR THEN GOTO ABORT
                OE.PROCESS.ORDER OID,GEN,DATE(),UET.DATA,,CHRG.CC.OK
                NO.UPD = YES
             CASE LED(8)<1,GEN> AND (NS # 'C' OR NS # 'I')
                MSG = 'Return Process'
                GOSUB CONFIRM
                IF ERR THEN GOTO ABORT
                OE.RETURN.TO.ORDER OID,GEN,QSIGN,LOG.MV
             END CASE
          END CASE

          *** If user is changing status of a transfer generation from
          *** a cancelled status we need to reopen the "Other gen"
          IF MODE = 'T' THEN
             IF NS='R' OR NS='S' OR NS='O' AND LED(6)<1,OTHER.GEN>='X' THEN
                LOGMV = OTHER.GEN
                LED(6)<1,OTHER.GEN> = 'O'
                OE.RETURN.TO.ORDER OID,OTHER.GEN,QSIGN,LOGMV
             END
          END

          IF NS#'D' AND NS#'I' THEN
             LOCATE LED(33)<1,GEN> IN LED(12)<1> SETTING DGEN THEN
                LED(33)<1,GEN>  = ''
                LED(33)<1,DGEN> = ''
                LED(48)<1,DGEN> = ''
                OE.DEL.GEN OID,DGEN
             END
          END

          IF NOT(SKIP.LOGGING) THEN
             IF OS='B' THEN
                LOG.MVCHG=GEN
                OE.ADD.COMMENT OID, LOG.MVCHG, '** Bid Status Changed To ':NS:' **'
             END ELSE
                LOG.MVCHG=GEN
                OE.ADD.COMMENT OID, LOG.MVCHG, '** Status Changed From ':OS:' To ':NS:' **'
                IF OTHER.GEN THEN
                   LOG.MVCHG=OTHER.GEN
                   OE.ADD.COMMENT OID, LOG.MVCHG, '** Status Changed From ':OS:' To ':NS:' **'
                END
             END
          END

          BEGIN CASE
          CASE NO.UPD
             NULL
          CASE UPD.ALL
             OE.UPD.ALL.LDIDS OID,GEN,QSIGN,LOG.MV
             * Cancel any open work order now.  The tag has been broken.
             IF CUT.TAGS THEN
                JAVA.CANCEL.TAG.WORK CUT.TAGS,OID
             END
             *** If updating a xfer we need to update the "other gen" also
             IF OTHER.GEN THEN
                OE.UPD.ALL.LDIDS OID,OTHER.GEN,QSIGN,LOG.MV
             END
          CASE OTHERWISE
             LED(6)<1,GEN> = 'ZZ'
             OE.FIND.SHIPDATE DUP.GEN,LED(9)<1,GEN>,LED(2)<1,GEN,2>,NS,,LED(70)<1,GEN>,LED(98)<1,GEN>
             LED(6)<1,GEN> = NS
             IF DUP.GEN THEN
                OE.UPD.ALL.LDIDS OID, GEN, QSIGN, LOG.MV
             END ELSE
                UPDATE.LEDGER    OID, GEN
             END
             *** If updating a xfer we need to update the "other gen" also
             IF OTHER.GEN THEN
                LED(6)<1,OTHER.GEN> = 'ZZ'
                OE.FIND.SHIPDATE DUP.GEN,LED(9)<1,OTHER.GEN>,LED(2)<1,OTHER.GEN,2>,NS,,LED(70)<1,OTHER.GEN>,LED(98)<1,OTHER.GEN>
                LED(6)<1,OTHER.GEN> = NS
                IF DUP.GEN THEN
                   OE.UPD.ALL.LDIDS OID,OTHER.GEN,QSIGN,LOG.MV
                END ELSE
                   UPDATE.LEDGER OID,OTHER.GEN
                END
             END
          END CASE

          *** Setup to respect the print status default control record
          *** if going from a bid status to an open order for sales and
          *** purchase order entry.
          INIT.PRT  = NO
          BEGIN CASE
          CASE MODE = 'S'
             IF OS  = 'B' AND NS # 'D' AND NS #'X' AND NS # 'I' THEN
                INIT.PRT = YES
             END
          CASE MODE = 'P'
             IF OS  = 'B' AND NS = 'O' THEN
                INIT.PRT = YES
             END
          END CASE
          OE.STATUS.INIT OID,GEN,NS,INIT.PRT

          IF MODE = 'S' THEN
             * Change freight allowed flag to 'Y' if order over min amt
             SOE.FRT.MIN.ORD LED(5)<1,GEN>,OID,GEN,'UPD'
          END

          IF NOT(NEW.ORDER) THEN
             IF OS='B' AND NS#'D' THEN
                RFBR = LED(2)<1,GEN,2>
                CTRB.ID = "RF.EXCL.TICKET~":RFBR
                READV EXCL FROM CTRBFILE,CTRB.ID,1 ELSE EXCL = ''
                IF EXCL[1,1] = 'F' THEN
                   RF.EXCL.PRINT.DOCS OID,GEN
                END
             END
          END
          *** Calls Stock Availability Service Level Tracking Subroutine
          SOE.UPDATE.STOCK.SL OID,,GEN,MODE,0,OS,NS
          IF OTHER.GEN THEN
             SOE.UPDATE.STOCK.SL OID,,OTHER.GEN,MODE,0,OS,NS
          END

          GOSUB CHK.ORDER.SPLIT

          GOSUB CHK.ACT.TRIGGER

          QUIT = NO; MOVE = 0; LASTKEY = 0
          RETURN

*-------------------------------------------------------------------------*
CHK.ACT.TRIGGER:   *** Determine if the bid to order activity trigger
          *** should be called.

          IF OS = "B" AND NS # "B" AND NS # "X" THEN
             AT.ID = "T034"
             AT.DATA = ""
             AT.DATA<2> = ST.CN:VM:BT.CN   ;* ship-to and bill-to
             AT.DATA<3> = LED(2)<1,GEN,2>       ;* stk branch
             AT.DATA<4> = OID
             AT.DATA<5> = GEN
             AT.DATA<7> = LED(6)<1,GEN>

             DOCS.PRDCD = ''

             ACTIVITY.TRIGGER AT.ID,AT.DATA,DOCS.PRDCD

          END
          RETURN
*-------------------------------------------------------------------------*
CHK.ORDER.SPLIT:

          GET.CUS LED(2)<1,GEN,2>,BT.CN,ST.CN,QSIGN
          READV CUS.SPLT FROM CUSFILE,ST.CN,183 ELSE CUS.SPLT = ''

          * Recalculate the tax on other invoiced gens for the order when
          * the current gen has been cancelled or reopened and the customer
          * or order is flagged for order level split tax.
          IF (LED(79)<1,GEN,5> OR CUS.SPLT) AND OS = 'I' THEN
             GEOCODE     = LED(79)<1,GEN,1>
             * Find all invoiced gens for the order
             * that haven't been printed
             READV PRT.STATS FROM LEDLFILE,OID,9 ELSE PRT.STATS = ''
             INV.CT  = DCOUNT(LED(8)<1>,VM)
             FOR ICT = 1 TO INV.CT
                IF LED(8)<1,ICT>+0 # 0 AND LED(6)<1,ICT> = 'I' THEN
                   IF PRT.STATS<1,ICT> # 'N' THEN
                      IF GEOCODE = LED(79)<1,ICT,1> AND ICT # GEN THEN
                         OE.TAX.CALC OID,ICT,QSIGN
                      END
                   END
                END
                UPDATE.LEDGER OID,ICT
             NEXT ICT
          END

          RETURN
*-------------------------------------------------------------------------*
CHECK.AP: * Check to see if a gen is reconciled or paid.
          IS.PAID   = NO
          IS.RECD   = NO

          AR.ID     = OID:'.':LED(8)<1,CHK.GEN>"R%3"
          READV AP.AIDS FROM ARFILE,AR.ID,2 ELSE AP.AIDS = ''
          AP.ID     = AP.AIDS<1,2>
          IF AP.ID  # '' THEN
             AP.OID = FIELD(AP.ID,'.',2)
             AR.ID  = OCONV(AP.ID,'G1.2')

             READV AR.STATUS FROM ARFILE,AR.ID,20 ELSE AR.STATUS = ''
             IF AR.STATUS # 'X' THEN
                IS.RECD   = YES

                * Don't check if ar has been cancelled
                IF AR.ID[1,1] = 'Y' THEN
                   * Now see if has been paid so we can tailor message
                   READV PAYON FROM ARFILE,AR.ID,22 ELSE PAYON = ''
                   IS.PAID = YES
                   FOR Q = 1 TO DCOUNT(PAYON,VM)
                      QID = AR.ID:'.':PAYON<1,Q>
                      READ NIL FROM PQFILE,QID THEN IS.PAID = NO; EXIT
                   NEXT Q
                END ELSE
                   READV AP.BAL FROM ARFILE,AR.ID,8 ELSE AP.BAL = ''
                   IF AP.BAL<1,2>+0=0 THEN IS.PAID = YES ELSE IS.PAID = NO
                END
             END
          END

          RETURN
*-------------------------------------------------------------------------*
CANCEL.IT: *** Cancel this generation


          * Can't directly cancel a payment or a PO-side
          * of a sales order.
          IF OS='$' OR OS='Y' THEN
             PRINT BELL:
             GOTO ABORT
          END

          CHECK.AUTH = YES
          GOSUB CHECK.PAYMENTS
          IF NOT(ACTION.OK) THEN GOTO ABORT

          IF LED(33)<1,GEN> THEN
             LOCATE LED(33)<1,GEN> IN LED(12)<1> SETTING DGEN THEN
                IF LED(8)<1,DGEN> THEN
                   AR.READV OID:'.':LED(8)<1,DGEN>"R%3",2,TST
                   IF TST#'' THEN
                      ERR.MSG  = 'The Direct P/O must be unreconciled'
                      ERR.MSG := ' first!!!'
                      GOTO ABORT
                   END
                END
             END
          END

          INVN = LED(8)<1,GEN>
          IF INVN='' THEN
             MSG = ''
             IF MODE = 'T' THEN
                MSG<1>  = 'You must cancel both the shipping and '
                MSG<1> := 'receiving generations.'
                MSG<2>  = 'Cancel Open Shipdate '
                IF GEN = 1 THEN
                   MSG<2> := '(shipping) ':OCONV(LED(9)<1,1>,'D4/')"L#10"
                END ELSE
                   MSG<2> := '(receiving) ':OCONV(LED(9)<1,2>,'D4/')"L#10"
                END
                MSG<2> := ' (Y/N) : '
             END ELSE
                MSG  = 'Cancel Open Shipdate '
                MSG := OCONV(LED(9)<1,GEN>,'D4/')"L#10":' (Y/N) : '
             END
             GOSUB CONFIRM
             IF ERR THEN GOTO ABORT
          END ELSE
             AUTH.KEY = AUTH.MODE:'OE.CLOSED.ORDER.CANCEL'
             CHECK.OE.CLOSED.AUTH.KEYS OID,GEN,AUTH.KEY,CANCEL.OK
             IF NOT(CANCEL.OK) THEN PRINT BELL:; GOTO ABORT

*** Logic to check and make sure they are able to edit the GEN before
*** letting them cancel it.
             IF MODE # 'A' THEN
                AUTH.KEY = AUTH.MODE:'OE.CLOSED.ORDER.EDIT'
                CHECK.OE.CLOSED.AUTH.KEYS OID,GEN,AUTH.KEY,ENTRY.OK
                IF NOT(ENTRY.OK) THEN PRINT BELL:; GOTO ABORT
             END

             ** This will need to be fixed
             IF NOT(JAVA.PROC$) AND NOT(PHANTOM.PROC) THEN
                MSG    = ''
                MSG<1> = BLINK$:'You are about to cancel Invoice # : ':OID:'.'
                MSG<1>:= INVN"R%3":NORM$:' '
                IF MODE = 'T' THEN
                   MSG<2>  = 'You must cancel both the shipping and '
                   MSG<2> := 'receiving generations.'
                END
                MSG<3> = 'Type CANCEL to continue : '
                PRINT BELL:;
                A = ''
IN.CNCL:        INP.PROMPT A,MSG,'MCU',6

                IF NOT(QUIT) AND A#'CANCEL' THEN PRINT BELL:; GOTO IN.CNCL

                IF QUIT THEN GOTO ABORT
             END
          END

          *** Loop Thru GENS and see if there are any remaing Open ones
          *** If this is the last open GEN and it being cancelled
          *** delete all Pre-Auths/Declines/Voids (Non-money collected)
          *** CC.PAYMENTS records
          GEN.CT = DCOUNT(LED(6)<1>,VM)
          OPEN.GENS = NO
          FOR GN = 1 TO GEN.CT
             *** Skip Current GEN - it has not be written to LEDGER yet
             IF GN = GEN THEN CONTINUE

             STAT = LED(6)<1,GN>
             *** GEN is not cancelled or payment
             IF STAT # 'X' AND STAT # '$' THEN
                OPEN.GENS = YES
                EXIT
             END
          NEXT GN
          *** There are not any Open GENS
          IF NOT(OPEN.GENS) THEN
             *** Delete credit card records that are not payments
             CREDIT.CARD.DEL.RECS OID
          END

          *** Update the UET Event for each product
          UET.ENABLED = NO
          IF UET.ENABLED$ THEN
             CTRB.ID = "UET.ENABLED~":LED(2)<1,GEN,2>
             READV UET.ENABLED FROM CTRBFILE,CTRB.ID,1 ELSE UET.ENABLED=NO
          END
          IF PIL.OK AND UET.ENABLED AND UCODE # '' THEN
             FOR X = 1 TO PIL.CHK.CT
                OID.DATA$<3> = ULDIDS<X>
                OID.DATA$<5> = UPNS<X>
                UET.LOG.AUTO UCODE
             NEXT X
          END

          *** If this is a transfer and if there is another gen to cancel
          *** then go back to check and see if it can be cancelled before
          *** cancelling either one.
          IF MODE = 'T' THEN
             IF OTHER.GEN AND OTHER.GEN # GEN THEN
                SV.GEN = GEN; GEN = OTHER.GEN
                ONE.CANCELLED = NO
                OE.CHECK.ALL.TAG OID, SV.GEN, CHNG.OK,NO.DISP.ERR,CUT.TAGS
                GOTO CANCEL.IT
             END
          END

CANCEL.GEN:  * cancel the gen
          OE.CANCEL.GEN OID,GEN,UET.DATA
          OE.UPD.ALL.LDIDS OID,GEN,QSIGN,LOG.MV

          *Cancel notification code
          SHIP.BR = LED(2)<1,GEN,2>

          *STAG.ID  = OID:".0":GEN "R%3"
          *LOC      = TRANS('PRINT.REVIEW',STAG.ID,13,'X')
          *IF LOC # "" THEN


          IF CUT.TAGS THEN
             * Cancel the tagged work orders
             JAVA.CANCEL.TAG.WORK CUT.TAGS,OID
          END

          CAN.LDIDS = RAISE(LED(48)<1,GEN>)
          OE.CANCEL.JOB.BID.LINES OID,GEN,CAN.LDIDS,"ALL",,YES

          IF NOT(OPEN.GENS) THEN
             IF LED(128)<1,1> THEN
                OE.JOB.REMOVE.CHILDREN OID,GEN
             END
             WAS.MJB                 = LED(128)<1,1>
             WAS.CHG                 = LED(129)<1,2>

             IF WAS.MJB OR WAS.CHG THEN
                LD.CT          = DCOUNT(LED(49)<1>,VM)
                GN             = 1
                FOR LDN        = 1 TO LD.CT
                   LDID        = LED(49)<1,LDN>
                   LD.GET LDID
                   MAT OLD.LD  = MAT LD
                   OE.GET.QTYS OID,SHP.IDS,SHP.QTYS,QSIGN,LDID
                   OE.UPD.QTYS OID,SHP.IDS,SHP.QTYS,QSIGN,GEN,LDID
                   OE.UPDATE.LDID LDID,OID,GEN,,QSIGN
                NEXT LDN
                OE.DEL.NULL.GENS OID,GEN
             END
             LED(128)                = ''
             LED(129)                = ''
          END

          LOCATE GEN IN LOG.MV<1> SETTING XX ELSE LOG.MV<1,-1> = GEN

*-------------------------------------------------------------------------*
          *** Code for cancelled generation notification.
          STAT = LED(6)<1,GEN,1>
          MSG = OID:".":GEN "R%3":' has been cancelled! Be sure to return all stock items into inventory!':STAT:'-':OS
          BT.CN     = LED(1)<1,GEN,1>

          IF STAT = 'X' THEN
          IF MODE = "S" AND OS="I" AND SHIP.BR="1" THEN
          SEND.MESSAGE 'Phantom','TOMMYO',MSG
          SEND.MESSAGE 'Phantom','GREGV',MSG
          SEND.MESSAGE 'Phantom','TSMITH',MSG
          SEND.MESSAGE 'Phantom','JUSTINH',MSG
          SEND.MESSAGE 'Phantom','TOMH',MSG
          END
          END


          *** If this is a transfer we need to cancel both shipping and
          *** receiving generations.  By this point all authorization
          *** and other checks have been passed so we just want to
          *** go back and cancel the "other gen"
          IF MODE = 'T' THEN
             IF OTHER.GEN AND NOT(ONE.CANCELLED) THEN
                GEN = SV.GEN
                ONE.CANCELLED = YES
                GOTO CANCEL.GEN
             END
          END


          GOSUB CHK.ORDER.SPLIT
          QUIT = NO; MOVE = 0; LASTKEY = 0
          RETURN
*-------------------------------------------------------------------------*
CHECK.PAYMENTS:

          * Check to see if this sales invoice has been reconciled on
          * a cash receipt.  If so, then user must have appropriate
          * authorization to cancel this sales invoice.
          IF LED(8)<1,GEN> AND MODE = 'S' THEN
             ACTION.OK = YES
             AR.ID     = OID:'.':LED(8)<1,GEN>"R%3"
             READV AR.IDS FROM ARFILE,AR.ID,2 ELSE AR.IDS = ''

             * Loop thru each associated A/R record to see if there
             * is a cash receipt attached to this invoice
             AR.CT    = DCOUNT(AR.IDS,VM)
             FOR ARN  = 2 TO AR.CT
                AR.ID = FIELD(AR.IDS<1,ARN>,'.',2,2)
                IF AR.ID[1,1] = 'C' THEN
                   READV AR.STAT FROM ARFILE,AR.ID,20 ELSE AR.STAT = ''
                   IF AR.STAT # 'X' THEN
                      KEY   = 'SOE.CLOSED.CANCEL.AR'
                      IF CHECK.AUTH THEN
                         PRMPT = 'Cancel an Invoice Attached to CR#':AR.ID
                      END ELSE
                         PRMPT = 'You Are About Return an Invoice Attached'
                         PRMPT := ' to CR#':AR.ID:' To An Order!'
                      END
                      IF NOT(JAVA.PROC$) THEN
                         IF CHECK.AUTH THEN
                            OE.GET.AUTH OID,PRMPT,KEY,ACTION.OK,GEN
                         END ELSE
                            ANS = "N"
                            PRMPT<3> = "Continue (Y/N) : "
IN$$1:                      INP.PROMPT ANS,PRMPT,"YN",1
                            ACTION.OK = ANS
                         END
                      END ELSE
                         IF NO.DISP.ERR<1> = PRMPT THEN
                            ACTION.OK = YES
                            NO.DISP.ERR = YES
                         END ELSE
                            NO.DISP.ERR = PRMPT
                            IF CHECK.AUTH THEN
                               NO.DISP.ERR<2> = KEY
                            END
                            NO.DISP.ERR = PRMPT
                            ACTION.OK = NO
                         END
                      END
                      EXIT
                   END
                END
             NEXT ARN
          END

          RETURN
*-------------------------------------------------------------------------*
CHK.PILS: *** Check the pils products if we cancel this order vs max days
          PIL.OK = YES

          *** Assume PIL is ok if PHANTOM.PROC and Solar already Checked
          IF PHANTOM.PROC OR JAVA.PROC$ OR INSIDE.ROE$ THEN RETURN

          LD.LIST    = ''  ; *List of LD's that Need Job Queue's Sent
          PIL.CHK.CT = ''  ; *Number of LD's that need PIL Check
          ULDIDS     = ''  ; *UET LDIDS List
          UPNS       = ''  ; *UET PNs List

          * Get a list of LD's
          OE.CHK.PIL.ORDER OID,GEN,QSIGN,OS,NEW.STAT,NEW.ORDER,RESP.NEEDED,ADDL.DATA,ADDL.INFO
          * If we need a response for any of the items on this generation
          * prompt the user.
          IF RESP.NEEDED THEN
             PIL.CHK.CT = DCOUNT(ADDL.DATA,AM)
             FOR PIL.CHK = 1 TO PIL.CHK.CT
                PIL.PN = ADDL.DATA<PIL.CHK,2>
                UPNS<-1> = PIL.PN
                OE.AUTH.PIL OID,GEN,PIL.PN,RAISE(ADDL.INFO<PIL.CHK>),PIL.OK
                IF NOT(PIL.OK<1>) THEN
                   PIL.OK = NO
                   EXIT
                END
                LD.LIST<-1> = ADDL.DATA<PIL.CHK,1>
                ULDIDS<-1> = ADDL.DATA<PIL.CHK,1>
             NEXT PIL.CHK
             * If the user ok's the PIL checks for all products then
             * send a tracker for each of the products.
             IF PIL.OK THEN
                OE.SEND.PIL.JQ OID,GEN,LD.LIST,NEW.STAT
             END
          END

          RETURN
*-------------------------------------------------------------------------*
CHK.LOT:  *** Check to make sure there are not any lots on order.
          MATBUILD SV.LD FROM LD
          LOT.OK = YES

          * Check to see if the P/O side of the direct has been processed.
          * If it has, then we can allow the user to process the S/O side
          * here. The reason being that A/P Entry has already happened
          * for the P/O side, and thus the S/O side can't be handled
          * through A/P Entry as the normal flow would provide for.
          IF (LED(6)<1,GEN> # "Y") THEN
             LOCATE LED(12)<1,GEN> IN LED(33)<1> SETTING YGEN THEN
                IF (LED(8)<1,YGEN> # "") THEN
                   PROC.LOT = YES
                   RETURN
                END
             END
          END

          IF LED(8)<1,GEN> THEN
             LDIDS = RAISE(LED(48)<1,GEN>)
          END ELSE
             LDIDS = LED(49)
          END
          LD.CT = DCOUNT(LDIDS<1>,VM)

          FOR LDN = 1 TO LD.CT
             TLDID = LDIDS<1,LDN>
             LD.GET TLDID
             PN = LD(1)
             * Comments and subtotals can't be lot items.
             IF NOT(NUM(PN)) OR PN = "" THEN CONTINUE
             * Check only the items that have shi qtys on this generation.
             QS = SUM(LD(5)<1,GEN>) + SUM(LD(6)<1,GEN>)
             IF QS = 0 THEN CONTINUE

             * Find the product status and convert it to a number.
             READV PRD.STAT FROM PRDFILE,PN,3 ELSE PRD.STAT = 2
             PRD.STAT = PRD.STAT + 0

             * Lot items product status = 9.
             IF PRD.STAT = 9 THEN LOT.OK = NO; EXIT
          NEXT LDN

          IF SV.LD # "" THEN
             MATPARSE LD FROM SV.LD
          END
          RETURN
*-------------------------------------------------------------------------*
CHK.RETURNS: *** Check to see if the canceled GEN can be reopened if it
          *** has return items. And whether this is a canceled GEN being
          *** reopened or an open GEN being canceled, if its a return,
          *** the return quantities on the original order will need to be
          *** updated.

          * Only valid for Sales Orders.
          IF (MODE # "S") THEN RETURN

          * No prompting by default...
          KEY.REQD = "SOE.RETURN.ALLOWED"
          LVL.REQD = 0

          * If this is a Java process and the required key is already
          * in the NO.DISP.ERR array, then we have already prompted the
          * user. If we are back here, then they must have had auth and
          * we can skip the check again. We don't want to simply return
          * here because we will need to update the quantites futher
          * below.
          IF JAVA.PROC$ THEN
             IF (NO.DISP.ERR<1,2> = KEY.REQD) THEN
                NO.DISP.ERR = ""
                GOTO RTN.UPD
             END
          END

          * Loop through all the lines on the GEN.
          LDIDS = RAISE(LED(48)<1,GEN>)
          LD.CT = DCOUNT(LDIDS<1>,VM)
          FOR LDN = 1 TO LD.CT
             * Get the LDID for the current line being checked.
             TLDID = LDIDS<1,LDN>
             LD.GET TLDID

             * Get the quantity and the return order info.
             SHP.QTY  = (SUM(LD(5)<1,GEN>) + SUM(LD(6)<1,GEN>))
             ORIG.ORD = LD(44)

             * If there is a return order and this is a valid return
             * check if there is a lock on the original order or if the
             * quantity exceeds what is allowed.
             IF ORIG.ORD # "" AND SHP.QTY > 0 THEN
                SOE.RETURN.CHECK.QTYS OID,GEN,TLDID,0,SHP.QTY,ORIG.ORD,RET.ERROR.MSG,LOCK.MSG

                * If a lock was found do not continue.
                IF LOCK.MSG THEN
                   ERR.MSG = LOCK.MSG
                   RETURN TO ABORT
                END

                * If this gen is going to be canceled and the return
                * exceeds the original order, then do not allow the
                * GEN to be reopened.
                IF OS = "X" AND RET.ERROR.MSG THEN
                   READV STAT FROM PRDFILE,LD(1),3 ELSE STAT = ""

                   * If the level required is less than 2, check to see
                   * what it should be set to. If it is already 2, it
                   * cannot go lower...
                   IF (LVL.REQD < 2) THEN
                      * If the item is a stock product, level 1 is
                      * required. Otherwise, level 2.
                      IF (STAT = 1) THEN
                         LVL.REQD = 1
                      END ELSE
                         LVL.REQD = 2
                      END
                   END
                END
             END
          NEXT LDN

          * Check to see if the user needs to be prompted/authorized.
          IF (LVL.REQD > 0) THEN

             * Set the prompt...
             PROMPT = RET.ERROR.MSG

             * In Eterm, just prompt right now...
             IF (NOT(PHANTOM.PROC) AND NOT(JAVA.PROC$)) THEN
                OE.GET.AUTH OID,PROMPT,KEY.REQD,ACTION.OK,,,LVL.REQD
                IF NOT(ACTION.OK) THEN RETURN TO ABORT

             * For Phantoms/Java, setup an authorized prompt...
             END ELSE
                NO.DISP.ERR      = PROMPT
                NO.DISP.ERR<1,2> = KEY.REQD
                NO.DISP.ERR<1,3> = LVL.REQD
                RETURN TO ABORT
             END
          END

          * Loop through the line items a second time. The reason for the
          * second loop is due to the fact that the first loop may have
          * been aborted due to insufficient authorization. So the logic
          * below would update some of the line item, but not all. By
          * waiting and looping again, we will only get here if we really
          * want to update the line items.
RTN.UPD:  FOR LDN = 1 TO LD.CT
             TLDID = LDIDS<1,LDN>
             LD.GET TLDID

             * Get the quantity and the return order info.
             SHP.QTY  = (SUM(LD(5)<1,GEN>) + SUM(LD(6)<1,GEN>))
             ORIG.ORD = LD(44)

             * If this is a return with an original order, update the
             * return quantities on the original order.
             IF ((ORIG.ORD # "") AND (SHP.QTY > 0)) THEN
                BEGIN CASE

                * If the return is being canceled, decrease the quantity
                * returned on the original order.
                CASE (NS = "X")
                   SOE.RETURN.UPD.QTYS OID,GEN,TLDID,,ORIG.ORD,SHP.QTY,0

                * If the return is being re-opened, increase the quantity
                * returned on the original order.
                CASE (OS = "X")
                   SOE.RETURN.UPD.QTYS OID,GEN,TLDID,,ORIG.ORD,0,SHP.QTY
                END CASE
             END
          NEXT LDN

          RETURN
*-------------------------------------------------------------------------*
CHK.SERS: *** Check each line item on this GEN to see if open serial #
          OE.FIND.OPEN.SERS OID,GEN,QSIGN,OPEN.SERS
          IF OPEN.SERS THEN
             PRMT = 'Invoice an Order With Open Serial Numbers'
             IF NOT(JAVA.PROC$) THEN
                OE.GET.AUTH OID,PRMT,'SOE.PROCESS.OPEN.SERS',SER.OK,GEN
             END ELSE
                IF NO.DISP.ERR<2> = 'SOE.PROCESS.OPEN.SERS' THEN
                   SER.OK = YES
                   NO.DISP.ERR = YES
                END ELSE
                   NO.DISP.ERR = PRMT
                   NO.DISP.ERR<2> = 'SOE.PROCESS.OPEN.SERS'
                END
             END
          END
          IF NOT(OPEN.SERS) THEN SER.OK = YES
          IF NOT(SER.OK) THEN ERR = YES ELSE ERR = NO
          RETURN
*-------------------------------------------------------------------------*
CHK.INV.FAC: *** Check the inventory factor for all line items and prompt
             *** if user needs to override anything.
          IF JAVA.PROC$ THEN
             PREV.JAVA.CHECKS<1,-1> = 'SOE.INV.FAC.CHECK'
          END
          LD.CT         = DCOUNT(LDIDS<1>,VM)
          INV.FAC.OK    = YES
          PRMPT         = ''
          PRD.PN.LIST   = ''
          PRD.DESC.LIST = ''
          FACTOR.LIST   = ''

          FOR LDN = 1 TO LD.CT
             CURR.LDID = LDIDS<1,LDN>
             LD.GET CURR.LDID
             PN = LD(1)
             QO = (SUM(LD(5)<1,GEN>) + SUM(LD(6)<1,GEN>))*QSIGN
             ORD.INV.FAC.CHECK GEN,PN,MODE,QO,'',UPDATE.OK,ALLOW.FCTR
             IF UPDATE.OK = NO THEN
                MATREAD PRD FROM PRDFILE,PN ELSE MAT PRD = ''
                PRD.PN.LIST<-1>   = PN
                PRD.DESC.LIST<-1> = PRD(1)<1,1>
                FACTOR.LIST<-1>   = ALLOW.FCTR
             END
          NEXT LDN

          *Determine if a popup box needs to be popped with the data
          *from the above loop.
          IF PRD.DESC.LIST # '' THEN
             PRD.CT = DCOUNT(PRD.DESC.LIST,AM)
             IF PRD.CT = 1 THEN
                DESC.DETAIL = "For product: ":PRD.DESC.LIST<1>:"."
                UT.GET.PROMPT '%21':AM:FACTOR.LIST<1>:AM:DESC.DETAIL,PRMPT
             END ELSE
                *Build the list of products/factors
                TEMP.LIST = ''
                IF JAVA.PROC$ THEN MAX.DISP = 20 ELSE MAX.DISP = 12
                IF PRD.CT < MAX.DISP THEN MAX.DISP = PRD.CT
                FOR PRD.II = 1 TO MAX.DISP
                   TEMP.LIST := '  ':PRD.DESC.LIST<PRD.II>:' / '
                   TEMP.LIST := FACTOR.LIST<PRD.II>:'%'
                   IF PRD.II < PRD.CT THEN
                      TEMP.LIST := ',':VM
                   END
                NEXT PRD.II
                IF PRD.CT > MAX.DISP THEN
                   TEMP.LIST := '  (More...)'
                END
                UT.GET.PROMPT '%810':AM:TEMP.LIST,PRMPT
             END
             IF NOT(JAVA.PROC$) THEN
                CONVERT VM TO AM IN PRMPT
                MSG = PRMPT
                GOSUB CONFIRM
                IF ERR THEN
                   INV.FAC.OK = NO
                END ELSE
                   GOSUB UPD.JQ
                END
             END ELSE
                IF NO.DISP.ERR<2> = 'SOE.INV.FAC.CHECK' THEN
                   NO.DISP.ERR = YES
                END ELSE
                   CONVERT VM TO SVM IN PRMPT
                   NO.DISP.ERR    = PRMPT
                   NO.DISP.ERR<2> = 'SOE.INV.FAC.CHECK'
                   NO.DISP.ERR<3> = LOWER(PRD.PN.LIST)
                   INV.FAC.OK     = NO
                END
             END
          END
          RETURN
*-------------------------------------------------------------------------*
UPD.JQ:   *** Update Job Queue.
          STK.BR = LED(2)<1,GEN,2>
          PRD.CT = DCOUNT(PRD.PN.LIST,AM)
          FOR PRD.II = 1 TO PRD.CT
             TPN = PRD.PN.LIST<PRD.II>
             OE.SEND.JOB.QUEUE OID,BT.CN,TPN,STK.BR
          NEXT PRD.II
          RETURN
*-------------------------------------------------------------------------*
CONFIRM:  *** Confirm
          ERR = NO
          IF PHANTOM.PROC OR JAVA.PROC$ THEN RETURN

          ANS = ''
IN$$3:    INP.PROMPT ANS,MSG,'YN',1
          IF NOT(ANS) OR QUIT THEN ERR = YES ELSE ERR = NO

          RETURN
*-------------------------------------------------------------------------*
ABORT:    ***  Get outta here
          IF SV.LED # "" THEN
             MATPARSE LED FROM SV.LED
          END

          *Loop and clear LD(139) if set.
          NS = NEW.STAT<1,1,1>
          OS = LED(6)<1,GEN,1>
          IF OS = 'B' THEN
             LDIDS= RAISE(LED(48)<1,GEN>)
             NUM.LNS = DCOUNT(LDIDS,VM)
             FOR L = 1 TO NUM.LNS
                LDID = LDIDS<1,L>
                PIL = ''
                LD.GET LDID
                IF NOT(NUM(LD(1))) OR LD(1) = '' THEN CONTINUE
                MAT OLD.LD = MAT LD
                IF LD(139)<1,GEN> THEN
                   LD(139)<1,GEN> = ""
                   UPDATE.LEDGER.DET OID,LDID,QSIGN
                END
             NEXT L
          END

          * Make sure the trap won't be set because we have to put back LED
          LED(82) = OLED(82)
          GEN.MV2 = GEN
          UPDATE.LEDGER OID,GEN.MV2

          RETURN
*-------------------------------------------------------------------------*
CHK.RCV.MSG:*** If the user has recv.msg set to POE, TOE or
          *** Both and the ship branch is not = to the terminal
          *** branch or the user branch or if the terminal branch is
          *** null, then build and display the message.

          RMSG = ''
          IF MODE = 'P' OR MODE = 'T' AND NEW.STAT = 'R' THEN
             READV RCV.MSG FROM INIFILE,USER.ID,87 ELSE RCV.MSG = ""

             BEGIN CASE
             CASE RCV.MSG = '' OR RCV.MSG = 'Never'
                NULL
             CASE RCV.MSG = 'Both'
                GOSUB FMT.RCV.MSG
             CASE RCV.MSG = 'POE' AND MODE = 'P'
                GOSUB FMT.RCV.MSG
             CASE RCV.MSG = 'TOE' AND MODE = 'T'
                GOSUB FMT.RCV.MSG
             CASE OTHERWISE
                NULL
             END CASE
          END

          RETURN
*-------------------------------------------------------------------------*
FMT.RCV.MSG: *** Format the Receiving Branch Warning Message

          UTRM.BR = TTY.DATA<13>
          UHOM.BR = SECURITY<7>

          IF UTRM.BR = "" THEN
             USR.BR = UHOM.BR
             RMSG.VAR = "Home"
          END ELSE
             USR.BR = UTRM.BR
             RMSG.VAR = "Terminal"
          END

          * check the user branch against the receiving branch
          * if they are equal return.
          IF USR.BR # LED(2)<1,GEN,2> THEN
             IF MODE = 'P' THEN MDESC = "Purchase" ELSE MDESC = "Transfer"
             IF NOT(JAVA.PROC$) THEN
                RMSG    = "The Receive Branch On This ":MDESC:" Order"
                RMSG<2> = "Does Not Match Your ":RMSG.VAR:" Branch!!!"
                RMSG<3> = ' Continue? (Y/N) :'
             END
          END

          RETURN
          IF LED(8)<1,GEN> # ''  THEN RETURN
*-------------------------------------------------------------------------*
UPD.OLD.STAT:
          IF LED(6)<1,GEN> = 'P' THEN RETURN

          READU LEDL FROM LEDLFILE,OID ELSE LEDL = ''
          LEDL<19,GEN> = LED(6)<1,GEN>
          WRITE LEDL ON LEDLFILE,OID

          RETURN
*-------------------------------------------------------------------------*
GET.CR.INFO:  *** Get Cash Receipt Information for Prompting

          READ ARREC FROM ARFILE,AR.ID ELSE RETURN

          GAS  = GET.GAS('CASH')
          CASH = ASUB.GET.AMT(ARREC,1.1,,GAS)

          PRMPT.LN  = AR.ID "L#20"            ; * Cash Receipt ID
          PRMPT.LN := ARREC<1,1> "L#15"       ; * Check Number
          PRMPT.LN := OCONV(ARREC<3,1>,'D4/') ; * Date
          PRMPT.LN := CASH "R26#10"           ; * Cash Receipt Amount

          PRMPT<-1> = PRMPT.LN

          RETURN
*-------------------------------------------------------------------------*
CHK.EXP.BID.PRC: *** Check for expired bid pricing
          *** We have to check to see if they are authorized to change
          *** cost and cogs before we let them continue with the pricing
          *** if they are not authorized then we are going to expire
          *** the pricing.
          IF LED(31)<1,GEN> >= DATE() THEN
             ALLOW.OVERRIDES = YES
             CHECK.KEY 'COGS.EDIT',COGS.OK
             CHECK.KEY 'SOE.COST.EDIT',COST.OK
             CHECK.KEY 'COGS.EDIT.NONSTOCK',COGS.NSTK.OK
             CHECK.KEY 'SOE.COST.EDIT.NONSTOCK',COST.NSTK.OK

             BEGIN CASE
             CASE (COST.OK AND COGS.OK AND COST.NSTK.OK AND COGS.NSTK.OK)
                *** user has auths, no need to check for overrides
                NULL
             CASE NOT(COST.OK) AND NOT(COGS.OK) AND NOT(COST.NSTK.OK) AND NOT(COGS.NSTK.OK)
                *** User does not have any override auths, if we
                *** find ANY override, expire bid pricing
                GOSUB CHK.PRC.OVERRIDES
             CASE OTHERWISE
                *** User has one or other auth, if control is set to copy
                *** override to both Cost and COGS, then one auth is all
                *** they need and we don't need to check for overrides.
                PRC.BR = LED(2)<1,GEN,1>
                CTRL.NAME = 'COST.OVERRIDE~':PRC.BR
                READV CHG.BOTH FROM CTRBFILE,CTRL.NAME,1 ELSE CHG.BOTH=''
                IF CHG.BOTH = 1 THEN
                   NULL ;* We don't need to check for overrides.
                END ELSE
                   * If control is set to 0, 2, or 3, we check for
                   * overrides. 2 and 3 deal with directs or tags, but
                   * we are here only from bids.  We don't need to make
                   * exceptions for direct or tags.
                   GOSUB CHK.PRC.OVERRIDES
                END
             END CASE

             IF NOT(ALLOW.OVERRIDES) THEN
                LED(31)<1,GEN> = DATE() - 1
                DISPLAY.OPTIONS = YES
             END
          END ELSE
             DISPLAY.OPTIONS = YES
          END

          RETURN
*-------------------------------------------------------------------------*
CHK.PRC.OVERRIDES:
          * loop through all of the line items to check
          * and see if there is a cogs or comm override
          LDIDS   = RAISE(LED(48)<1,GEN>)
          LDID.CT = DCOUNT(LDIDS,VM)
          MATBUILD SV.LD FROM LD
          FOR LL = 1 TO LDID.CT
             LDID = LDIDS<1,LL>
             LD.GET LDID
             IF NOT(NUM(LD(1))) OR LD(1) = '' THEN CONTINUE;* Skip non-pns
             IF LD(44) # ''                   THEN CONTINUE;* Skip returns

             * Only check cost and cogs overrides
             IF LD(11)<1,GEN>#'' THEN COGS.OVRD = YES ELSE COGS.OVRD = NO
             IF LD(28)<1,GEN>#'' THEN COST.OVRD = YES ELSE COST.OVRD = NO
             IF NOT(COGS.OVRD) AND NOT(COST.OVRD) THEN CONTINUE

             * If we have even one override, we can stop.
             * User has to authorize expired bid pricing.
             READV PRD.STAT FROM PRDFILE,LD(1),3 ELSE PRD.STAT = 1
             IF PRD.STAT = 2 THEN
                * Non-stock
                IF (COGS.OVRD AND NOT(COGS.NSTK.OK)) OR (COST.OVRD AND NOT(COST.NSTK.OK)) THEN
                   ALLOW.OVERRIDES = NO
                   EXIT
                END
             END ELSE
                * Stock
                IF (COGS.OVRD AND NOT(COGS.OK)) OR (COST.OVRD AND NOT(COST.OK)) THEN
                   ALLOW.OVERRIDES = NO
                   EXIT
                END
             END
          NEXT LL
          MATPARSE LD FROM SV.LD

          RETURN
*-------------------------------------------------------------------------*
AUTH.EXP.BID.PRC: *** We have an expired bid, prompt user to see what
          *** action they want to take.

          CHOICES = ''
          CHOICES<1,1> = 'Abort Operation'
          CHOICES<1,2> = 'Reprice Bid'
          CHOICES<1,3> = 'Authorize Use of Expired Pricing'
          PRINT BELL:
          TITLE = '** Expired Pricing **'
          MENU.TABLE X,22,7,1,3,35,,,CHOICES,TITLE
          LOCATE X IN CHOICES<1> SETTING OPT ELSE OPT = 1

          BEGIN CASE
          CASE OPT = 1
             ERR.MSG = 'Operation Aborted'
          CASE OPT = 2
             * check if we should prompt the user to decide
             * whether or not they want the system to
             * automatically reprice the sell prc.  If they
             * are authed & get prompted and answer 'N', then
             * the system will keep the bid sell prc.
             INCL.PRC.OVRD = YES
             KEY.ID = 'SOE.REPRICE.BID.SELL.PRC'
             CHECK.KEY KEY.ID,ENTRY.OK
             IF ENTRY.OK THEN
                MSG = 'Reprice Sell Price for All Items?'
                INCL.PRC.OVRD = 'Y'
IN$$2:          INP.PROMPT INCL.PRC.OVRD,MSG,'YN',1
                IF F12 THEN
                   INCL.PRC.OVRD = YES
                END
             END
             * Reprice bid
             OE.REPRICE.BID OID,GEN,QSIGN,INCL.PRC.OVRD,YES,YES
             MATBUILD SV.LED FROM LED
          CASE OPT = 3
             PRMPT    = 'Use Expired Pricing'
             KEY.REQD = 'SOE.BID.APPRV.EXPIRED'
             OE.GET.AUTH OID,PRMPT,KEY.REQD,ACTION.OK,GEN
             IF NOT(ACTION.OK) THEN
                ERR.MSG = 'Operation Aborted'
             END
          END CASE

          RETURN
*-------------------------------------------------------------------------*
!TSMITH~06/30/15~11:24
